package cur.nature.component.redis.common;

import org.redisson.api.RBlockingQueue;
import org.redisson.api.RDelayedQueue;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component;

@Component
@DependsOn("redissonClient")
@ConditionalOnProperty( value = {"cur.component.redis.enable"})
public class DelayQueueUtil {

    private static RedissonClient redissonClient;

    private DelayQueueUtil(@Qualifier("redissonClient") RedissonClient redissonClients) {
        redissonClient = redissonClients;
    }

    public static RDelayedQueue<String> getDelayQueue() {
        RBlockingQueue<String> blockQueue = redissonClient.getBlockingQueue("test");
        RDelayedQueue<String> delayedQueue = redissonClient.getDelayedQueue(blockQueue);
        return delayedQueue;
    }

    public static RBlockingQueue<String> getBlockQueue() {
        RBlockingQueue<String> blockQueue = redissonClient.getBlockingQueue("test");
        return blockQueue;
    }
}
